package org.app.test.zookeeper1;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
 
import org.apache.zookeeper.KeeperException;
 
public class Client
{
 
    /**目前可用
     * @param args
     * @throws InterruptedException 
     * @throws IOException 
     * @throws KeeperException 
     */
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException
    {
        BaseZookeeper baseZookeeper = new BaseZookeeper();
         
        String host = "192.168.159.128:4182";
         
        // 连接zookeeper
        baseZookeeper.connectZookeeper(host);
        System.out.println("--------connect zookeeper ok-----------");
         
        // 创建节点
        byte [] data = {1, 2, 3, 4, 5};
//        String result = baseZookeeper.createNode("/test", data);
//        System.out.println(result);
//        System.out.println("--------create node ok-----------");
         
        // 获取某路径下所有节点  org.app.api.TestRegistryService
        List<String> children = baseZookeeper.getChildren("/dubbo/org.app.api.TestRegistryService");
        for (String child : children)
        {
            System.out.println(child);
        }
        System.out.println("--------get children ok-----------");
      //dubbo
//        byte [] dubbo = baseZookeeper.getData("/dubbo");
//        System.out.println("dubbo的值:"+new String(dubbo));
        
      //test1 99
        byte [] zookeeper = baseZookeeper.getData("/zookeeper");
        System.out.println("zookeeper的值:"+new String(zookeeper));
        
        //test1 99
        byte [] test1 = baseZookeeper.getData("/test1");
        System.out.println("test1的值:"+new String(test1));
        
        //test
        byte [] test = baseZookeeper.getData("/test");
        System.out.println("test的值:"+new String(test));
        
        //test2 "常德市,郴州市,衡阳市,怀化市,娄底市,邵阳市"
        // 获取节点数据
        byte [] test2 = baseZookeeper.getData("/test2");
        System.out.println("test2的值:"+new String(test2));
        System.out.println("--------get node data ok-----------");
         
        // 更新节点数据
//        data = "test data".getBytes();
//        baseZookeeper.setData("/test", data, 0);
//        System.out.println("--------set node data ok-----------");
//         
//        nodeData = baseZookeeper.getData("/test");
//        System.out.println(Arrays.toString(nodeData));
//        System.out.println("--------get node new data ok-----------");
//         
        baseZookeeper.closeConnect();
        System.out.println("--------close zookeeper ok-----------");
    }
 
}